#include "SDLGameObject.h"
#include "TextureManager.h"
#include "Game.h"


SDLGameObject::SDLGameObject(const LoadedParams* Params) : GameObject(Params), position(Params->getX(), Params->getY()), 
	velocity(0,0), acceleration(0,0)
{
	
	Width = Params->getWidth();
	Height = Params->getHeight();
	textureID = Params->getTextureID();

	currentRow = 1;
	currentFrame = 1;
	active = true;
}

SDLGameObject::~SDLGameObject(void)
{
}

void SDLGameObject::Draw()
{
	TextureManager::Instance()->DrawFrame(textureID, (int)position.getX(), (int)position.getY(), Width, Height, currentRow, currentFrame, Game::Instance()->getRenderer());
}

void SDLGameObject::Update()
{
}

void SDLGameObject::Shutdown()
{
}

bool SDLGameObject::CheckCollision(SDLGameObject* o)
{
	int leftA, leftB;
	int rightA, rightB;
	int topA, topB;
	int bottomA, bottomB;

	leftA = this->getPosition().getX();
	rightA = this->getPosition().getX() + this->getWidth();
	topA = this->getPosition().getY();
	bottomA = this->getPosition().getY() + this->getHeight();

	//Calculate the sides of rect B
	leftB = o->getPosition().getX();
	rightB = o->getPosition().getX() + o->getWidth();
	topB = o->getPosition().getY();
	bottomB = o->getPosition().getY() + o->getHeight();

	//If any of the sides from A are outside of B
	if( bottomA <= topB ){return false;} 
	if( topA >= bottomB ){return false; }
	if( rightA <= leftB ){return false; }
	if( leftA >= rightB ){return false;}
	return true;
}

bool SDLGameObject::isActive()
{
	return active;
}